package com.shanzmoo.merchant.manage.api.web.sys;

import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.core.domain.dto.SysUserSaveDTO;
import com.shanzmoo.core.domain.dto.SysUserUpdateDTO;
import com.shanzmoo.db.domain.dto.UserQueryDTO;
import com.shanzmoo.db.domain.vo.UserPageVo;
import com.shanzmoo.db.module.psys.domain.vo.user.UserUpdatePasswordDto;
import com.shanzmoo.merchant.manage.api.manager.SysUserManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *
 *
 * @author： Gzhao 2021/3/29
 */
@Api(tags = "系统管理--用户")
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys-user")
public class SysUserController {

    private final SysUserManager sysUserManager;

    @ApiOperation(value = "用户修改个人密码")
    @PostMapping("/update-password")
    public SHttpResponse<Boolean> updatePassword(@Valid @RequestBody UserUpdatePasswordDto updateDto) {
        SResponse<Boolean> re = sysUserManager.updatePassword(updateDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "用户分页列表")
    @PostMapping("/page-list")
    public SHttpResponse<PageRespBase<UserPageVo>> pageList(@Valid @RequestBody UserQueryDTO queryDTO) {
        SResponse<PageRespBase<UserPageVo>> re = sysUserManager.getPageList(queryDTO);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "新增系统用户")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody SysUserSaveDTO saveDTO) {
        SResponse<Boolean> re = sysUserManager.add(saveDTO);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "修改系统用户信息")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody SysUserUpdateDTO updateDTO) {
        SResponse<Boolean> re = sysUserManager.update(updateDTO);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "启用（禁用）")
    @GetMapping("/status-change")
    public SHttpResponse<Boolean> statusChange(@RequestParam(value = "id") Integer id) {
        sysUserManager.statusChange(id);
        return SHttpResponse.ok(Boolean.TRUE);
    }
    @ApiOperation(value = "重置密码")
    @GetMapping("/init-password")
    public SHttpResponse<Boolean> initPassword(@RequestParam(value = "id") Integer id) {
        sysUserManager.initPassword(id);
        return SHttpResponse.ok(Boolean.TRUE);
    }

}
